<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<h1>我爱北京天安门</h1>
</body>
<script>
  function logData() {
    console.log('lalala')
    window.navigator.sendBeacon('/log', '关闭之前的挣扎')
  }

  // window.onbeforeunload = logData
  window.addEventListener('onbeforeunload', logData, false)
</script>
</html>
